package com.atguigu.mySmartCampus.controller;

import com.atguigu.mySmartCampus.Service.ClazzService;
import com.atguigu.mySmartCampus.entity.Clazz;
import com.atguigu.mySmartCampus.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api("班级控制")
@RequestMapping("/sms/clazzController")
public class ClazzController {
    @Autowired
    ClazzService clazzService;

    // /sms/clazzController/getClazzs
//. @GetMapping("/getClazzs")
    @ApiOperation("获取班级列表")
    @GetMapping("/getClazzs")
    public Result getClazzs() {
        List<Clazz> clazzes = clazzService.selectClazz();
        return Result.ok(clazzes);
    }

    @ApiOperation("新增或者修改班级")
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(@ApiParam("新增或者修改班级对象")@RequestBody Clazz clazz){
        clazzService.saveOrUpdate(clazz);
        return Result.ok();
    }

    @ApiOperation("删除n个班级")
    @DeleteMapping("/deleteClazz")
    public Result deleteClazz(@ApiParam("要删除的n个班级列表")@RequestBody List<Integer> clazzList){

//        boolean b = clazzService.saveOrUpdateBatch(clazzList);
        clazzService.removeByIds(clazzList);
        return Result.ok();
    }
    @ApiOperation("分页带条件查询班级信息")
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzByOpr(
            @ApiParam("分页查询的页码数") @PathVariable("pageNo") Integer pageNo,
            @ApiParam("分页查询页大小")@PathVariable("pageSize") Integer pageSize,
            @ApiParam("分页查询的查询条件") Clazz clazz
    ){
        Page<Clazz> page =new Page<>(pageNo,pageSize);

        IPage<Clazz> iPage=clazzService.getClazzsByOpr(page,clazz);

        return Result.ok(iPage);

    }
}



